<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base target="_self">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<link href="./js/calendar/css/jscal2.css" rel="stylesheet" type="text/css">
<link href="./js/calendar/css/border-radius.css" rel="stylesheet" type="text/css">
<link href="./js/calendar/css/gold/gold.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="./js/calendar/js/jscal2.js"></script>
<script type="text/javascript" src="./js/calendar/js/lang/en.js"></script>

<script type="text/javascript" src="./js/calendar.js"></script>
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var contractCode = document.getElementById("contractCode");
		var contractName = document.getElementById("contractName");
		var customerName = document.getElementById("customerName");
		var contractDate = document.getElementById("contractDate");
		var salePerson = document.getElementById("salePerson");
		
		var purchaseDescs = document.getElementsByName("purchaseDesc");
		var nums = document.getElementsByName("num");
		var costValues = document.getElementsByName("costValue");
		var discounts = document.getElementsByName("discount");
		var costss = document.getElementsByName("costs");
		var prossProfits = document.getElementsByName("prossProfit");
		var currentDate = document.getElementById("currentDate");
		
		if(contractCode.value == ""){
			alert("合同编码<fmt:message key='common.message.empty'/>");
			return false;
		}
		if(contractName.value == ""){
			alert("合同名称<fmt:message key='common.message.empty'/>");
			return false;
		}
		if(customerName.value == ""){
			alert("客户名称<fmt:message key='common.message.empty'/>");
			return false;
		}
		if(contractDate.value == ""){
			alert("签约时间<fmt:message key='common.message.empty'/>");
			return false;
		}
		if(contractDate.value != "" && currentDate.value != ""){
			var d1 = "";
			var d2 = "";
			d1 = (contractDate.value).replace("-","/");
			d2 = (currentDate.value).replace("-","/");
			if(Date.parse(d1) - Date.parse(d2) > 0){
				alert("签约日期不能晚于当前系统日期！");
				return false;
			}
		}
		
		if("<c:out value='${isImportContract}'/>" == 1 && salePerson != null && salePerson.value == ""){
			alert("销售代表<fmt:message key='common.message.empty'/>");
			return false;
		}
		
		var sign = 0;
		var totalContractCost = 0;
		for(var i = 0; i < purchaseDescs.length; i++){
			if(purchaseDescs[i].value != "" 
				|| nums[i].value != "" 
				|| costValues[i].value != "" 
				//|| discounts[i].value != "" 
				|| costss[i].value != "" 
				|| prossProfits[i].value != ""){
				
				if(purchaseDescs[i].value == ""){
					alert("采购内容<fmt:message key='common.message.empty'/>");
					return false;
				}
				if(nums[i].value == ""){
					alert("数量<fmt:message key='common.message.empty'/>");
					return false;
				}
				if(costValues[i].value == ""){
					alert("金额<fmt:message key='common.message.empty'/>");
					return false;
				}
				/**if(discounts[i].value == ""){
					alert("折扣率<fmt:message key='common.message.empty'/>");
					return false;
				}*/
				if(costss[i].value == ""){
					alert("成本<fmt:message key='common.message.empty'/>");
					return false;
				}
				if(prossProfits[i].value == ""){
					alert("毛利<fmt:message key='common.message.empty'/>");
					return false;
				}
			}
			
			if(purchaseDescs[i].value != "" 
				&& nums[i].value != "" 
				&& costValues[i].value != "" 
				//|| discounts[i].value != "" 
				&& costss[i].value != "" 
				&& prossProfits[i].value != ""){
				
				if(discounts[i].value == ""){
					alert("折扣率<fmt:message key='common.message.empty'/>");
					return false;
				}
			}
			
			if(purchaseDescs[i].value != "" 
				&& nums[i].value != "" 
				&& costValues[i].value != "" 
				&& discounts[i].value != "" 
				&& costss[i].value != "" 
				&& prossProfits[i].value != ""){
				sign = sign + 1;
				totalContractCost = totalContractCost + Number(costValues[i].value);
			}
		}
		
		if(sign <= 0){
			alert("合同明细不能为空，请追加合同明细！");
			return false;
		}
		
		if(totalContractCost < 0.01){
			alert("合同金额不能小于0!");
			return false;
		}
		
		return true;
	}

	function back(){
		window.location.href = "./contract.do";
		window.location.target = "main";
	}
	
	function save(){
		this.document.forms[0].submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='common.message.addSuccess'/>");
		}
		if("<c:out value='${failResult}'/>" == 3){
			alert("保存失败：上传文件大小不能超过10M!");
		}
		if("<c:out value='${repeatResult}'/>" == 1){
			alert("保存失败：合同编码已存!");
		}
		
//		document.getElementById("saveBtn").href = "javascript:save();";
	}
	
/*	function caseTypeDialog(){
		var url = "./contract.do?action=selectCaseType";
		var dlgParam = "dialogHeight:360px;dialogWidth:430px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){
			//æ ¹æ�®ä»Žå­�çª—å�£å¾—åˆ°çš„å€¼ï¼Œä»Žä¸­æ��å�–å®¢æˆ·idå’Œå®¢æˆ·å��ç§°
			var typeId = "";
			var caseType = "";
			var caseCode = "";
			var tStr = rt.split(",");
			if(tStr[0] != 0 && tStr[1] != 0){
				typeId = tStr[0];
				caseType = tStr[1];
				caseCode = tStr[2];
			}
			document.getElementById("typeId").value = typeId;										
			document.getElementById("caseType").value = caseType;
			document.getElementById("caseCode").value = caseCode;
		}
	}	*/
	
	function processDialog(){
		var processGroupId =document.getElementById("processGroupId").value;
		var processId=document.getElementById("processId").value;
		var url = "./contract.do?action=selectProcess&processGroupId="+processGroupId+"&processId="+processId;
		var dlgParam = "dialogHeight:360px;dialogWidth:430px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){
			//æ ¹æ�®ä»Žå­�çª—å�£å¾—åˆ°çš„å€¼ï¼Œä»Žä¸­æ��å�–å®¢æˆ·idå’Œå®¢æˆ·å��ç§°
			//var processGroupId = "";
			var processId = "";
			var processName = "";
			var tStr = rt.split(",");
			if(tStr[0] != 0 && tStr[1] != 0){
				processId = tStr[0];
				processName = tStr[1];
			}								
			document.getElementById("processId").value = processId;
			document.getElementById("processName").value = processName;
		}
	}
	var checkIsSubmit= function(){
		if($("#isSuccess").val()==1){
			alert('保存成功');
			var selectValue = "";
			var processId = document.getElementById('processId').value;
			var processName = document.getElementById('processName').value;
			var applicationCode = document.getElementById('applicationCode').value;
			var applicationDate = document.getElementById('applicationDate').value;
			var description = document.getElementById('description').value;
			var attachId = 	document.getElementById('attachId').value;
			selectValue = processId+","+processName+","+applicationCode+","+applicationDate+","+description+","+attachId;
			window.returnValue = selectValue;		
			self.close();
		}
			
	};
	window.onload = checkIsSubmit;
-->
</script>
</head>
<body onload="initPage()">
<form name="addContractCaseForm" action="./contract.do?action=uploadCaseFile" enctype="multipart/form-data" method="post">
<input type="hidden" id="isSuccess" value="${isSuccess}"/>
<input id="mark" name="mark" type="hidden" value="${mark}"/>
<input id="caseId" name="caseId" type="hidden" value="${caseId}"/>
<input id="attachId" name="attachId" type="hidden" value="${attachId}"/>
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">案件</td>
					</tr>
					<tr>
						<td align="center" valign="bottom">
							<input type="button" class="btn_submit" value="确定" onclick="save()" hidefocus="true"/>&nbsp;&nbsp;
							<input type="button" class="btn_back" value="取消并返回" onclick="back()" hidefocus="true"/>
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td>
							<table class="table_add">
							<input id="isSub" name="isSub" type="hidden" value="${isSub}"/>
								<tr><td colspan="4" class="title_top">案件信息</td></tr>
								<tr>
									<td class="title">案件阶段：</td>
									    <c:choose>
											<c:when test="${isSub == 0}">
										     	<td class=""> <input id="processName" name="processName" class="input_long" type="text" value="${processName}"/></td>
										        <td><input type="button" class="btn_select"  value="" onclick="processDialog()" hidefocus="true"/></td>
											</c:when>
											<c:otherwise>
											</c:otherwise>
									    </c:choose>
								
									<td> <input id="processGroupId" name="processGroupId" type="hidden" value="${processGroupId}"/> </td>
									<td><input id="processId" name="processId" type="hidden" value="${processId}"/></td>		
								</tr>
								<tr>
									<td class="title">申请号：</td>
									<td class="">
										<input id="applicationCode" name="applicationCode" class="input_long" type="text" value="${applicationCode}"/>
									</td>	
									<td>&nbsp;</td>
									<td>&nbsp;</td>								
								</tr>
								<tr>
									<td class="title">申请日：</td>
									<td class="">
										<input id="applicationDate" name="applicationDate" class="input_long" type="text" 
											onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly" value="${applicationDate}"/> 									 									
									</td>
									<td class="title">实用新型名：</td>
									<td class="">
										<input id="description" name="description" class="input_long" type="text" value="${description}"/>
									</td>									
								</tr>																							
								<tr>
									<td class="title"><font style="font-size: 10px;">(附件 &lt; 10M)</font>&nbsp;&nbsp;上传附件：</td>
									<td colspan="3">
										<input id="contents" name="contents" type="file" style="width: 96%"/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>	
</body>
</html>